import java.util.Random;


public class singlethreaded {

	public double MonteCarloStandardOption(String CallPutFlag, double S, 
			double X, double T, double r, double b, double v, int nSteps, int nSimulations)
	{
		
		int z = 0;
        double st;
        double dt = T/ nSteps;
        double drift = (b - (v*v) / 2) * dt;
        double vSqrdt = v * Math.sqrt(dt);
        Random rand = new Random();
        double sum = 0;

        if ("c".equals(CallPutFlag)){
            z=1;
        }
        else if ("p".equals(CallPutFlag)){
            z=-1;
        }
        for (int i=1; i<=nSimulations; i++){
            st = S;
            for (int j=1; j<=nSteps; j++){
                st = st * Math.exp(drift + vSqrdt * rand.nextGaussian());
            }
            sum = sum + Math.max(z*(st-X), 0);
        }
        return( Math.exp((-r*T)*(sum/nSimulations)));

	}
	
}
